package com.li.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ndboo.reslibrary.R;

/**
 * Author: Li
 * Date: 2017/9/12 0012
 * Description:
 */

public class SettingItemView extends FrameLayout {
    private ImageView mImgLeft;
    private ImageView mImgRight;
    private TextView mTxt;
    public SettingItemView(@NonNull Context context) {
        this(context,null);
    }

    public SettingItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    private void init(Context context, AttributeSet attrs) {

        View view= LayoutInflater.from(context).inflate(R.layout.item_setting,this);

        setClickable(true);
        setBackground(ContextCompat.getDrawable(context,R.drawable.selector_setting));
        mImgLeft=view.findViewById(R.id.img_left);
        mImgRight=view.findViewById(R.id.img_right);
        mTxt=view.findViewById(R.id.txt);
        TypedArray array=context.obtainStyledAttributes(attrs,R.styleable.SettingItemView);
        int imgLeftResId=array.getResourceId(R.styleable.SettingItemView_set_img_left,R.drawable.ic_setting);
        int imgRightResId=array.getResourceId(R.styleable.SettingItemView_set_img_right,R.drawable.ic_arrow_right);
        String txt=array.getString(R.styleable.SettingItemView_set_txt);
        array.recycle();

        mImgLeft.setImageResource(imgLeftResId);
        mImgRight.setImageResource(imgRightResId);
        mTxt.setText(txt);
    }
}
